package com.ruoyi.common.core.domain.model;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.Date;

@ApiModel(value = "TimeRange", description = "时间范围")
public class TimeRange {

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("字段开始时间")
    private Date beginTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("字段结束时间")
    private Date endTime;

    public TimeRange() {
    }

    public TimeRange(Date beginTime, Date endTime) {
        this.beginTime = beginTime;
        this.endTime = endTime;
    }

    public Date getBeginTime() {
        return beginTime;
    }

    @ApiModelProperty(hidden = true)
    public Date getBeginTimeOfHour() {
        return beginTime == null ? null : DateUtil.beginOfHour(beginTime);
    }

    @ApiModelProperty(hidden = true)
    public Date getBeginTimeOfDay() {
        return beginTime == null ? null : DateUtil.beginOfDay(beginTime);
    }

    @ApiModelProperty(hidden = true)
    public Date getBeginTimeOfWeek() {
        return beginTime == null ? null : DateUtil.beginOfWeek(beginTime);
    }

    @ApiModelProperty(hidden = true)
    public Date getBeginTimeOfMonth() {
        return beginTime == null ? null : DateUtil.beginOfMonth(beginTime);
    }

    @ApiModelProperty(hidden = true)
    public Date getBeginTimeOfYear() {
        return beginTime == null ? null : DateUtil.beginOfYear(beginTime);
    }

    public void setBeginTime(Date beginTime) {
        this.beginTime = beginTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    @ApiModelProperty(hidden = true)
    public Date getEndTimeOfHour() {
        return endTime == null ? null : DateUtil.endOfHour(endTime);
    }

    @ApiModelProperty(hidden = true)
    public Date getEndTimeOfDay() {
        return endTime == null ? null : DateUtil.endOfDay(endTime);
    }

    @ApiModelProperty(hidden = true)
    public Date getEndTimeOfWeek() {
        return endTime == null ? null : DateUtil.endOfWeek(endTime);
    }

    @ApiModelProperty(hidden = true)
    public Date getEndTimeOfMonth() {
        return endTime == null ? null : DateUtil.endOfMonth(endTime);
    }

    @ApiModelProperty(hidden = true)
    public Date getEndTimeOfYear() {
        return endTime == null ? null : DateUtil.endOfYear(endTime);
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public static boolean isNull(TimeRange timeRange){
        if (timeRange == null){
            return true;
        }
        if (timeRange.beginTime == null && timeRange.endTime == null ){
            return true;
        }
        return false;
    }

    public static boolean isNotNull(TimeRange timeRange){
        return !isNull(timeRange);
    }

}
